package com.example.husbandry_online.view;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;

import com.example.husbandry_online.R;
import com.tencent.mmkv.MMKV;

public class LoginAndRegisterActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_and_register);
        //创建默认Fragment
        createFragment(new LoginFragment());
        //顶部状态栏透明
        topStatusBarTransparent();
    }
    public void topStatusBarTransparent(){
        //顶部状态栏透明
        if(Build.VERSION.SDK_INT >= 21) {
            Window window = getWindow();
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.setStatusBarColor(Color.TRANSPARENT);
        }
    }
    //创建Fragment
    public void createFragment(Fragment fragment){
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.LoginAndRegisterFrag,fragment);
        fragmentTransaction.commit();
    }
    //更改Fragment
    public void changeFragment(Fragment fragment) {
        //得到管理类
        FragmentManager fragmentManager = getSupportFragmentManager();
        //开始事务
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        //事务创建
        fragmentTransaction.replace(R.id.LoginAndRegisterFrag,fragment);

        fragmentTransaction.addToBackStack(null);
        //事务提交
        fragmentTransaction.commit();
    }
}